package com.qf.myblogssm.service.serviceImp;

import com.qf.myblogssm.dao.TuserMapper;
import com.qf.myblogssm.pojo.Tuser;
import com.qf.myblogssm.service.LoginService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * create by 王镜 on 2019/6/14 0014 16:35
 */
//注解，表明当前层是服务层
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private TuserMapper tuserMapper;

    @Override
    public Tuser login(String name) {
        return tuserMapper.selectByPrimaryName(name);
    }

    @Override
    public Tuser login(String name, String password) {
        Tuser tuser=tuserMapper.selectByUsername(name);
        if(tuser!=null)
        {
            Md5Hash md5Hash = new Md5Hash(password, name, 100);
            if(md5Hash.toString().equals(tuser.getUserPassword())){
                return tuser;
            }else {
                return null;
            }
        }
        return null;
    }

    //   @Override
//    public Tuser login(Integer id) {
//        return tuserMapper.selectByPrimaryKey(id);
//    }
}
